package CaseTraining;

import java.util.Random;

public class CaseDemo02 {
    public static void main(String[] args) {
        System.out.println(createCode(5));
    }

    public static String createCode(int n){
        Random r = new Random();
        //定义一个String类型记住每次产生的随机字符
        String code = "";
        //给出数字几就循环几遍
        for (int i = 1; i <= n; i++) {
            //随3个机数，让每次循环都产生三个数中的一个
            int type = r.nextInt(3);
            switch (type){
                case 0 :
                    //产生随机数0-9
                    code += r.nextInt(10);
                    break;
                case 1 :
                    //随机给出大写英文字母A65 - Z65+25
                    char ch1 = (char) (r.nextInt(26) + 65);
                    code += ch1;
                    break;
                case 2 :
                    //随机给出小写英文字母a97 - z97+25
                    char ch2 = (char) (r.nextInt(26) + 97);
                    code += ch2;
                    break;
            }
        }
        return code;
    }
}
